package com.pwc.conversionTool.controller;

import java.util.Arrays;
import java.util.Locale;

import javax.servlet.ServletContext;

import org.dom4j.DocumentException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.pwc.conversionTool.Manager.SoapUIManager;
import com.pwc.conversionTool.Manager.XMLConfigImpl;


@Controller
public class SoapController {
	
	
	private static final Logger logger = LoggerFactory.getLogger(SoapController.class);
	
	@Autowired
	public ServletContext context;


	/**
	 * give a page for test soap connection
	 * @param locale
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/soap/templateTest", method = RequestMethod.GET)
	public String home(Locale locale, Model model) {		
		try {
			model.addAttribute("isInitial", SoapUIManager.isInitial());
			model.addAttribute("endpoint", XMLConfigImpl.initial(context).getEndpoint());
			model.addAttribute("userName",XMLConfigImpl.initial(context).getUserName());
			model.addAttribute("password",XMLConfigImpl.initial(context).getPassword());
			model.addAttribute("passwordType",XMLConfigImpl.initial(context).getPasswordType());
		} catch (Exception e) {			
			logger.error("log4j is running in templateTest");
			logger.error(Arrays.toString(e.getStackTrace()));
		}
		return "/soap/templateTest";
	}
	

}
